package com.moqianfan.mcuassistant.fragment.learn;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.moqianfan.mcuassistant.R;
import com.moqianfan.mcuassistant.activity.CourseActivity;
import com.moqianfan.mcuassistant.activity.SourceListActivity;
import com.moqianfan.mcuassistant.adapter.CommDataAdapter;
import com.moqianfan.mcuassistant.bean.GridBean;
import com.moqianfan.mcuassistant.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnItemClick;

/**
 * Created by Administrator on 2016/11/11.
 * 51单片机
 */

public class LearnMcuFragment extends BaseFragment implements AdapterView.OnItemClickListener {
    @BindView(R.id.grid_learn)
    GridView GVLearnMcu;

    @Override
    public View findViews(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_learn_item, container, false);
    }

    @Override
    public void initViews() {
        ArrayList<GridBean> mGridBeen = new ArrayList<>();
        mGridBeen.add(new GridBean(R.drawable.mcu_base, "单片机基础"));
        mGridBeen.add(new GridBean(R.drawable.mcu_design, "设计实例"));
        mGridBeen.add(new GridBean(R.drawable.mcu_chip, "常用芯片"));
        mGridBeen.add(new GridBean(R.drawable.mcu_electronics, "电路基础"));
        mGridBeen.add(new GridBean(R.drawable.ic_asm, "汇编教程"));

        CommDataAdapter<GridBean> mAdapter = new CommDataAdapter<GridBean>(mGridBeen, R.layout.view_item_gridview) {
            @Override
            public void bindView(ViewHolder holder, GridBean obj) {
                holder.setImageResource(R.id.image_icon, obj.getResId());
                holder.setText(R.id.txt_icon, obj.getiName());
            }
        };
        GVLearnMcu.setAdapter(mAdapter);
    }

    @Override
    public void loadData() {

    }

    @OnItemClick(R.id.grid_learn)
    public void onItemClick(AdapterView<?> view, View view1, int i, long l) {
        switch (i) {
            case 0:
                Intent intent0 = new Intent();
                intent0.setClass(getActivity(), CourseActivity.class);
                intent0.putExtra("title", "单片机基础");
                startActivity(intent0);
                break;
            case 1:
                Intent intent1 = new Intent();
                intent1.setClass(getActivity(), SourceListActivity.class);
                intent1.putExtra("title", "设计实例");
                startActivity(intent1);
                break;
            case 2:
                Intent intent2 = new Intent();
                intent2.setClass(getActivity(), SourceListActivity.class);
                intent2.putExtra("title", "常用芯片");
                startActivity(intent2);
                break;
            case 3:
                Intent intent3 = new Intent();
                intent3.setClass(getActivity(), SourceListActivity.class);
                intent3.putExtra("title", "电子基础");
                startActivity(intent3);
                break;
            case 4:
                Intent intent4 = new Intent();
                intent4.setClass(getActivity(), CourseActivity.class);
                intent4.putExtra("title", "汇编教程");
                startActivity(intent4);
                break;
        }
    }
}
